import React from 'react'
import { InputItem, NavBar, TextareaItem, Button } from 'antd-mobile'
import AvatarSelector from '../../component/avatar-selector/avatar-selector'
import {connect} from 'react-redux'
import { update } from '../../redux/user.redux'
import { Navigate } from 'react-router-dom'
import withRouter from '../../component/withRouter'

@withRouter
@connect(
    state=>state.user,
    {update}
)
class BossInfo extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            title: '',
            desc: '',
            company: '',
            money: '',
        }
    }
    onChange(key, val) {
        this.setState({
            [key]: val
        })
    }
    render(h) {
        // console.warn(this.props)
        const path = this.props.location.pathname
        const redirect = this.props.redirectTo
        return (
            <div>
                {redirect&&redirect!==path? <Navigate to={redirect} />:null}
                <NavBar mode="dark" >BOSS完善信息页</NavBar>
                <AvatarSelector 
                    // selectAvatar={4}
                    selectAvatar={imgname => {
                        this.setState({
                            avatar: imgname
                        })
                    }}
                ></AvatarSelector>
                <InputItem onChange={v=>this.onChange('title', v)}>招聘职位</InputItem>
                <InputItem onChange={v=>this.onChange('company', v)}>公司名称</InputItem>
                <InputItem onChange={v=>this.onChange('money', v)}>职位薪资</InputItem>
                <TextareaItem onChange={v=>this.onChange('desc', v)} 
                    title='职位要求' row={3} autoHeight></TextareaItem>
                <Button
                onClick={()=>{
                    this.props.update(this.state)
                }}
                 type='primary'>保存</Button>
            </div>
        )
    }
}

export default BossInfo